app.controller('sys_regionController', ['$scope', '$q', 'httpWrapService', 'dialogs', '$state', '$stateParams','ngTreetableParams',
        function($scope, $q, httpWrapService, dialogs, $state, $stateParams, ngTreetableParams) {

    $scope.params = new ngTreetableParams({
        getNodes: function(parent) {
        	if(parent && parent.children){
        		return parent.children;
        	}
        	var data = [];
        	var param = {};
        	if(parent && parent.id) {
        		param.parentId = parent.id;
        	}
        	httpWrapService.asyncPost("system/region/list.do", param, function(res){
        		data = res.data;
        		if(parent) parent.children = res.data;
            });
        	return data;
        },
        getTemplate: function(node) {
            return 'region_tree_node';
        },
        options: {
        }
    });
	

    $scope['delete'] = function(node, parentNode) {
    	var id = node.id;
        httpWrapService.defaultDelete('system/region/delete/'+ id +'.do').then(function(res){
        	$scope.params.refresh();
        });
    };

}]);
